package haois.module.navigate.service;

import haois.module.navigate.dao.mapper.NavigateMapper;
import haois.module.navigate.daomain.Navigate;
import haois.module.rbac.daoman.Manager;
import haois.module.rbac.service.ManagerService;
import haois.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by RuiHaoZ on 2018/4/20 10:54
 */
@Service
public class NavigateService {

    @Autowired
    private NavigateMapper navigateMapper;
    @Autowired
    private ManagerService managerService;

    public void addNavi(Navigate navigate) {
        navigate.setCreateTime(DateUtil.getYMdHms());
        navigateMapper.addNavi(navigate);
    }

    public void addUrl(Navigate navigate) {
        navigateMapper.addUrl(navigate);
    }

    public void updateNavi(Navigate navigate) {
        navigate.setUpdateTime(DateUtil.getYMdHms());
        navigateMapper.updateNavi(navigate);
    }

    public void updateUrl(Navigate navigate) {
        navigateMapper.updateUrl(navigate);
    }

    public List<Map<String, Object>> getUrlByNaviId(Integer id) {
        return navigateMapper.getUrlByNaviId(id);
    }

    public List<Map<String, Object>> getNaviByMan(String account) {
        Manager manager = managerService.getByAccount(account);
        return navigateMapper.getNaviByMan(manager.getId());
    }

    public Map<String, Object> getUrl(Integer id) {
        return navigateMapper.getUrl(id);
    }

    public Map<String, Object> getNavi(Integer id) {
        return navigateMapper.getNavi(id);
    }

    @Transactional
    public void deleteNavi(Integer id) {
        navigateMapper.deleteNavi(id);
        navigateMapper.deleteUrlByNaviId(id);
    }

    public void deleteUrl(Integer id) {
        navigateMapper.deleteUrl(id);
    }

    public Integer getId(String mark){
        return navigateMapper.getIdByMark(mark);
    }

}
